﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using SRP_LibBusinessEntity;

namespace SRP_LibDataAccess
{
    public class CUbigeo
    {

        #region Singleton

        private static CUbigeo _instance = null;
        public static CUbigeo Intance
        {
            get
            {
                if (_instance == null)
                    _instance = new CUbigeo();
                return _instance;
            }
        }
        #endregion

        public DataTable ListarPais(string cod_pais, string cod_estado)
        {
            DataSet ds = new DataSet();
            WSCentria.wsUtilitario ws = new WSCentria.wsUtilitario();
            ws.Url = System.Configuration.ConfigurationManager.AppSettings["rutaWSCentria"].ToString();
            ds = ws.ListarPais(cod_pais, cod_estado);

            return ds.Tables[0];
        }

        public DataTable ListarDepartamentos(string CodPais)
        {
            DataSet ds = new DataSet();
            WSCentria.wsUtilitario ws = new WSCentria.wsUtilitario();
            ws.Url = System.Configuration.ConfigurationManager.AppSettings["rutaWSCentria"].ToString();
            ds = ws.ListarDepartamentos(CodPais);

            return ds.Tables[0];
        }

        private List<EUbigeo> MakeDepartamentos(DataTable dt)
        {
            List<EUbigeo> departamentos = new List<EUbigeo>();
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    EUbigeo ubigeo = new EUbigeo();
                    ubigeo.CodUbigeo = dr["VUBI_CODIGO_UBIGEO"].ToString();
                    ubigeo.Departamento = dr["VUBI_NOMDPTO"].ToString();
                    departamentos.Add(ubigeo);
                }
            }
            return departamentos;
        }

        public DataTable ListarProvincias(string CodDepartamento)
        {
            DataSet ds = new DataSet();
            WSCentria.wsUtilitario ws = new WSCentria.wsUtilitario();
            ws.Url = System.Configuration.ConfigurationManager.AppSettings["rutaWSCentria"].ToString();
            ds = ws.ListarProvincias(CodDepartamento);

            return ds.Tables[0];
        }

        public DataTable ListarDistritos(string CodProvincia)
        {
            DataSet ds = new DataSet();
            WSCentria.wsUtilitario ws = new WSCentria.wsUtilitario();
            ws.Url = System.Configuration.ConfigurationManager.AppSettings["rutaWSCentria"].ToString();
            ds = ws.ListarDistritos(CodProvincia);

            return ds.Tables[0];
        }

    }
}
